package com.caidanxiaoyuan.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONArray;
import com.caidanxiaoyuan.model.AreaList;
import com.caidanxiaoyuan.service.AreaListService;
import com.caidanxiaoyuan.util.JsonUtil;
import com.caidanxiaoyuan.util.ResponseUtil;

@RequestMapping("/area")
@CrossOrigin
@Controller
public class AreaListController {
	
	@Autowired
	private AreaListService areaListService;
	
	/**
	 * @throws Exception 
	 * 
	* @Description: 获取地址  
	* @author zealot
	* @param @param e
	* @param @param response 
	* @return void    
	* @version 创建时间：2017年3月2日 上午9:51:59  
	* @throws
	 */
	@RequestMapping("/list")
	public void list(AreaList e,HttpServletResponse response) throws Exception{
		List<AreaList> list = areaListService.selectByUs(e);
		String st = "{";
		String ed = "}";
		String ap = "";
		String cd = "";
		if(list!=null){
			ap = "\"" + ap;
			for(int i=0;i<list.size();i++){
				e = list.get(i);
				ap += e.getId()+"\":[\""+e.getMingcheng()+"\",\""+e.getParentid()+"\"],\"";
			}
			ap = ap.substring(0, ap.length()-2);
		}
		ResponseUtil.write(response,st+ap+ed);
	}
}
